﻿define(function (require, exports, module) {
    var Canvas = require('util/canvas');
    var ImageStorage = require('util/imageStorage');
    var Config = require('util/config');
    var Character = require('character');

    var m_characterImage = Canvas.get('#character')[0];

    exports.loadAsync = eval(Wind.compile('async', function (data) {
        var character = new Character(data);

        var characterAnimation = new Kinetic.Animation(function (frame) {
            var index = Math.floor(time / 150);
            var img = $await(ImageStorage.getAsync(character.actionPaths[index % character.action.count]));
            if (img != m_characterImage.getImage()) {
                var x = Config.settings.WIDTH / 2, y = Config.settings.HEIGHT / 2;
                x -= (img.width / 2);
                y -= img.height;
                m_characterImage.setAttrs({
                    x: x, y: y, width: img.width, height: img.height, image: img
                });
            }
        }, m_characterImage.getLayer());
    }));
});